package dao;

import generators.UserGenerator;

import java.util.List;

import junit.framework.Assert;

import model.dao.UserDAO;
import model.entity.User;

import org.junit.Before;
import org.junit.Test;


public class UserDAOtest {
	
	public UserDAO dao;
	
	@Before
	public void doBefore() {
		dao = new UserDAO(User.class);
	}
	
	@Test
	public void testDuplicateEmail() {
		UserGenerator generator = new UserGenerator();
		User u = generator.generate(1).get(0);
		UserDAO dao = new UserDAO(User.class);
		dao.create(u);
//		u = generator.generate(1).get(0);
//		dao.create(u);		
	}
	
	@Test
	public void testFindByMail() {
		List<User> us = dao.findAll();
		if(us == null || us.size() == 0) {
			Assert.fail("DB doesn't have users");
		}
		Assert.assertNotNull(dao.findByMail(us.get(0).getMail()));
	}

}
